import { useRequest } from 'umi';
import { requestFunComponFiex, getTenantID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
import { ApplyManageTab } from '../mconfig';
import { searchCriteriaFun } from '../../Acommon';
import { getBaseUrl } from '@/services/urlconst';
const baseUrl = getBaseUrl();

export const ApplyManageService = (curRes, state = {}) => {
  /***获取数据字典**/
  const loadMdicIds: string[] = [`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}`];

  /**管理页列表接口 */
  const getApplyManageService = (pageSize: number = 10) => {
    const request: any = useRequest(
      (requestParams?: Record<string, any>) => {
        let params: any = {
          current: 1,
          pageSize: pageSize,
          dicTypeIds: loadMdicIds?.toString(),
          sort: 'createTime',
          order: 'desc',
          ...requestParams,
          ...ApplyManageTab(curRes),
          ...state,
        };

        const reqUrl = `${baseUrl}/purchaseApplyController/dataGrid/${params?.params}`;

        params = searchCriteriaFun(params);

        return requestFunComponFiex('POST', reqUrl, params);
      },

      {
        manual: false,
        paginated: true,
        defaultPageSize: pageSize,
      },
    );

    return {
      applyManageRun: request.run,
      applyManageDataSource: request.data?.rows || [],
      applyManageLoading: request.loading,
      applyManageTableProps: request.tableProps,
    };
  };

  return {
    getApplyManageService,
  };
};
